clear, close all
gasNames={'argon' 'helium' 'hydrogen'};

Tconductivity = [500, 700, 800, 1000, 1300, 1500, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3500, 4000, 4300, 4500, 4700, 4800, 5000, 5100, 5500, 6000, 6300, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10200, 10500, 10800, 11000, 11500, 12000, 12500, 13000, 13500, 14000, 14500, 14800, 15000, 15300, 15500, 16000, 16300, 16500, 17000, 17300, 17500, 17800, 18000, 18500, 18800, 19000, 19500, 20000];
conductivity = [
    [.026712, .035011, .038823, .044982, .067598, .057725, .062661, .065122, .067576, .070022, .072456, .074877, .077282, .079669, .082038, .084387, .086714, .089019, .091301, .093561, .095798, .098014, .10021, .10458, .11682, .12970, .13129, .13287, .13366, .13525, .13604, .14378, .15494, .16338, .17012, .19198, .22278, .26555, .32480, .40512, .51052, .64428, .70582, .80759, .92007, 1.0023, 1.2217, 1.4650, 1.7239, 1.9722, 2.1970, 2.3633, 2.4625, 2.4866, 2.4899, 2.4803, 2.4671, 2.4262, 2.4054, 2.3958, 2.3920, 2.4048, 2.4197, 2.4506, 2.4767, 2.5582, 2.6166, 2.6584, 2.7740, 2.9006]
    [.22562, .28954, .31996, .37864, .46266, .51667, .56942, .59538, .62111, .64661, .67190, .69700, .72192, .74667, .77126, .79571, .82001, .84418, .86823, .89216, .91598, .93970, .96331, 1.0103, 1.1262, 1.1949, 1.2404, 1.2857, 1.3082, 1.3532, 1.3757, 1.4649, 1.5759, 1.6424, 1.6871, 1.8016, 1.9292, 2.0122, 2.1206, 2.2295, 2.3399, 2.4533, 2.5001, 2.5722, 2.6476, 2.7000, 2.8409, 2.9996, 3.1816, 3.3925, 3.6379, 3.9228, 4.2512, 4.4700, 4.6251, 4.8716, 5.0449, 5.5086, 5.8064, 6.0127, 6.5523, 6.8927, 7.1261, 7.4859, 7.7321, 8.3681, 8.7648, 9.0343, 9.7186, 10.398]
    [.25776, .33676, .37576, .45350, .57117, .65205, .74153, .79535, .86174, .94869, 1.0673, 1.2323, 1.4619, 1.7776, 2.2036, 2.7655, 3.4882, 4.3932, 5.4944, 6.7934, 8.2730, 9.8906, 10.1572, 10.4660, 10.4830, 10.0185, 7.3487, 5.3030, 4.5613, 3.5120, 3.1526, 2.3683, 2.0890, 2.0663, 2.0799, 2.1721, 2.3171, 2.5061, 2.7401, 3.0237, 3.3596, 3.7364, 3.8922, 4.1374, 4.3860, 4.5678, 5.0042, 5.4429, 5.8852, 6.3690, 6.7784, 7.1503, 7.3755, 7.4174, 7.3773, 7.2945, 7.1972, 6.8305, 6.5459, 6.3396, 5.8017, 5.5854, 5.2845, 5.0041, 4.8335, 4.4669, 4.2931, 4.1949, 4.0063, 3.8886]
    ];

figure(1), plot(Tconductivity.', conductivity.');
title('conductivity')
ylabel('temperature')
legend(gasNames)

Tdensity = [ 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1800, 2000, 2300, 2500, 2600, 2700, 2800, 2900, 3000, 3500, 3600, 3700, 3800, 3900, 4000, 4500, 5000, 5300, 5500, 6000, 6300, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 11500, 12000, 12500, 13000, 13500, 14000, 14500, 15000, 15500, 16000, 16500, 17000, 17500, 18000, 18500, 19000, 19500, 20000];
density = [
    [.97353, .81121, .69530, .60839, .54079, .48672, .44248, .40561, .37441, .34767, .32450, .27042, .24338, .21164, .19471, .18722, .18029, .17385, .16786, .16226, .13908, .13522, .13157, .12810, .12482, .12170, .10818, .097361, .091850, .088510, .081133, .077268, .074888, .069527, .064865, .060757, .057083, .053740, .050639, .047696, .044838, .042003, .039145, .036243, .033310, .030387, .027556, .024906, .022539, .020510,.018832,.017477,.016392,.015516,.014795,.014182,.013660,.013207,.012775,.012369]
    [ .097557, .081297, .069683, .060973, .054198, .048778, .044344, .040649, .037522, .034842, .032519, .027099, .024389, .021208, .019511, .018761, .018066, .017421, .016820, .016259, .013937, .013550, .013183, .012836, .012507, .012195, .010840, .0097557, .0092035, .0088688, .0081297, .0077426, .0075044, .0069683, .0065038, .0060973, .0057386, .0054197, .0053144, .0048775, .0046448, .0044330, .0042390, .0040606, .0038953, .0037413, .0035968, .0034601, .0033296, .0032040, .0030819, .0029620, .0028433, .0027246, .0026054, .0024851, .0023635, .0022410, .0021180, .0019955]
    [.048646, .040509, .034703, .030353, .026971, .024267, .022056, .020214, .018656, .017321, .016164, .013464, .012109, .010488, .0095792, .0091543, .0087407, .0083331, .0079270, .0075189, .0054520, .0050607, .0046924, .0043540, .0040502, .0037833, .0029267, .0025135, .0023467, .0022525, .0020547, .0019542, .0018929, .0017557, .0016370, .0015325, .0014392, .0013544, .0012761, .0012025, .0011321, .0010637, .00099643, .00092990, .00086399, .00079913, .00073595, .00067568, .00061939, .00056788, .00052235, .00048286, .00044924, .00042094, .00039720, .00037723, .00036084, .00034625, .00033353, .00032227]
    ];

figure(2), plot(Tdensity.', density.');
title('density')
ylabel('temperature')
legend(gasNames)


Tenthalpy = [500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 4000, 4300, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 9800, 10000, 10200, 10300, 10500, 10700, 10800, 11000, 11100, 11200, 11300, 11400, 11500, 11800, 12000, 12500, 12700, 12800, 13000, 13200, 13300, 13500, 13700, 13800, 14000, 14300, 14500, 15000, 15200, 15300, 15500, 16000, 16500, 17000, 17500, 18000, 18500, 19000, 19500, 20000];
enthalpy = [
    [104990, 157050, 209100, 261150, 313190, 365240, 417270, 469310, 521350, 573390, 625420, 677460, 729490, 781520, 833560, 885590, 937630, 989660, 1041700, 1093700, 1145800, 1197800, 1249800, 1301900, 1353900, 1405900, 1458000, 1510000, 1562000, 1614100, 1666100, 1926300, 2082400, 2186400, 2446600, 2707000, 2967900, 3230700, 3498100, 3776100, 4075000, 4412000, 4812700, 5314100, 5683800, 5966300, 6282700, 6456000, 6832300, 7254800, 7486800, 7993700, 8265000, 8557200, 8866600, 9194000, 9532600, 10690000, 11558000, 14176000, 15383000, 16036000, 17421000, 18913000, 19698000, 21341000, 23040000, 23935000, 25777000, 28636000, 30575000, 35379000, 37225000, 38123000, 39856000, 43770000, 47028000, 49664000, 51782000, 53513000, 54979000, 56273000, 57537000, 58849000]
    [4144900, 4664200, 5183500, 5702800, 6222100, 6741500, 7260800, 7780100, 8299400, 8818700, 9338000, 9857300, 10377000, 10896000, 11415000, 11935000, 12454000, 12973000, 13493000, 14012000, 14531000, 15050000, 15570000, 16089000, 16608000, 17128000, 17647000, 18166000, 18686000, 19205000, 19724000, 22321000, 23879000, 24917000, 27514000, 30111000, 32707000, 35304000, 37900000, 40497000, 43094000, 45693000, 48296000, 50906000, 52478000, 53531000, 54587000, 55118000, 56183000, 57256000, 57796000, 58883000, 59431000, 59983000, 60538000, 61097000, 61660000, 63381000, 64559000, 67638000, 68937000, 69604000, 70977000, 72409000, 73149000, 74682000, 76295000, 77134000, 78884000, 81709000, 83744000, 89459000, 92035000, 93393000, 96261000, 104420000, 114250000, 126080000, 140310000, 157330000, 177550000, 201370000, 229130000, 261070000]
    [3005500, 4509400, 6038300, 7593500, 9175900, 10786000, 12426000, 14094000, 15793000, 17521000, 19281000, 21074000, 22902000, 24773000, 26698000, 28696000, 30792000, 33028000, 35455000, 38142000, 41175000, 44658000, 48714000, 53485000, 59129000, 65819000, 73734000, 83050000, 93921000, 106450000, 120640000, 206570000, 250940000, 271970000, 302810000, 319620000, 332220000, 343580000, 354700000, 366110000, 378310000, 391890000, 407620000, 426530000, 439860000, 449830000, 460680000, 466530000, 478960000, 492720000, 499930000, 515730000, 524200000, 532830000, 542090000, 551780000, 561920000, 594770000, 619390000, 689930000, 722420000, 739590000, 775790000, 814510000, 833750000, 876090000, 920870000, 944130000, 992340000, 1068500000, 1121500000, 1257700000, 1314000000, 1342300000, 1398700000, 1536900000, 1666500000, 1783700000, 1886700000, 1975300000, 2050500000, 2114400000, 2169200000, 2216500000]
    ];
figure(3), plot(Tenthalpy.', enthalpy.');

title('enthalpy')
ylabel('temperature')
legend(gasNames)

TspecificHeat = [500, 1000, 1500, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3800, 4000, 4300, 4500, 4600, 4700, 4800, 4900, 5000, 5100, 5200, 5300, 5400, 5500, 6000, 6500, 7000, 7500, 8000, 8200, 8500, 8800, 9000, 9100, 9200, 9300, 9500, 9800, 10000, 10300, 10500, 10600, 10700, 10800, 10900, 11000, 11100, 11200, 11300, 11400, 11500, 11800, 12000, 12300, 12500, 12700, 12800, 13000, 13200, 13300, 13500, 13800, 14000, 14200, 14300, 14500, 15000, 15300, 15500, 16000, 16100, 16200, 16300, 16400, 16500, 16800, 17000, 17500, 17800, 18000, 18300, 18500, 18800, 19000, 19500, 19700, 19800, 20000];
specificHeat = [
    [520.33, 520.41, 520.36, 520.34, 520.34, 520.34, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.33, 520.34, 520.35, 520.36, 520.38, 520.41, 520.45, 520.50, 520.57, 520.66, 520.79, 520.95, 522.76, 528.01, 540.91, 568.59, 621.33, 653.19, 715.15, 798.13, 867.85, 907.33, 953.81, 997.24, 1102.7, 1303.0, 1457.7, 1733.3, 1946.9, 2065.6, 2159.1, 2319.8, 2460.3, 2608.7, 2713.2, 2922.1, 3094.1, 3274.5, 3385.4, 4067.6, 4394.2, 5229.8, 5743.6, 6064.5, 6525.2, 7062.5, 7590.7, 7846.9, 8333.6, 8953.9, 9289.8, 9536.4, 9622.0, 9711.8, 9444.7, 8974.8, 8560.5, 7311.9, 7045.3, 6778.3, 6512.9, 6250.7, 5993.3, 5262.1, 4817.8, 3884.6, 3450.3, 3211.1, 2924.0, 2777.7, 2622.1, 2344.9, 2535.8, 2582.5, 2617.6, 2711.6]
    [5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.1, 5193.2, 5193.3, 5193.9, 5195.5, 5196.7, 5199.6, 5204.4, 5209.1, 5212.0, 5215.4, 5219.3, 5228.9, 5248.9, 5267.0, 5303.4, 5335.3, 5354.0, 5374.6, 5397.5, 5422.8, 5450.6, 5481.2, 5514.7, 5551.5, 5591.7, 5635.5, 5791.7, 5919.2, 6151.5, 6337.8, 6552.5, 6671.4, 6934.7, 7234.5, 7399.2, 7760.5, 8389.7, 8873.0, 9412.5, 9704.6, 10336, 12220, 13583, 14599, 17549, 18214, 18906, 19625, 20372, 21146, 23646, 25441, 30557, 34006, 36471, 40415, 43142, 47612, 50694, 58808, 62174, 63872, 67283]
    [14450, 16105, 17597, 19972, 20968, 22354, 24269, 26870, 30329, 34832, 40564, 47710, 56441, 66895, 79148, 91362, 108710, 125280, 141960, 177770, 174630, 131220, 96869, 82223, 69849, 59704, 51554, 45094, 40014, 36037, 32928, 30496, 28593, 23701, 22318, 22331, 23278, 25305, 26419, 28646, 31455, 33729, 34807, 36353, 37555, 41037, 46159, 51015, 58490, 64090, 67175, 70414, 72156, 77139, 80830, 84682, 86290, 92583, 99600, 101380, 111690, 125730, 142310, 153460, 165520, 171670, 184150, 196740, 192400, 214790, 232680, 243770, 253920, 258560, 266810, 263550, 282600, 281750, 271100, 267650, 263810, 259630, 255130, 250340, 234610, 223320, 194180, 177090, 166180, 150190, 140740, 127760, 119920, 103030, 97283, 94610, 89639]
    ];

figure(4), plot(TspecificHeat.', specificHeat.');
title('specific heat')
ylabel('temperature')
legend(gasNames)

Tviscosity = [500, 700, 1000, 1300, 1500, 1800, 2000, 2300, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500, 10000, 10500, 11000, 11500, 12000, 12500, 13000, 14000, 13500, 14500, 15000, 15500, 16000, 16500, 17000, 17500, 18000, 18500, 19000, 19500, 20000];
viscosity = [
    [.000034224, .000044858, .000057633, .000067598, .000073960, .000083437, .000089715, .000099017, .00010511, .00011987, .00013389, .00014715, .00015972, .00017169, .00018314, .00019415, .00020481, .00021517, .00022529, .00023518, .00024480, .00025402, .00026252, .00026965, .00027431, .00027489, .00026947, .00025646, .00023552, .00020811, .00017748, .00014715, .00012038, .000098656, .000082258, .000070625, .000062838, .000057957, .000055177, .000053865, .000053537, .000054238, .000054778, .000055304]
    [.000028964, .000037170, .000048608, .000059394, .000066327, .000076432, .000083008, .000092676, .000099011, .00011453, .00012969, .00014457, .00015924, .00017372, .00018806, .00020228, .00021639, .00023042, .00024438, .00025828, .00027212, .00028590, .00029964, .00031332, .00032693, .00034044, .00035381, .00036696, .00037979, .00039213, .00040376, .00041433, .00042337, .00043024, .00043413, .00043408, .00042905, .00041815, .00040085, .00037721, .00034805, .00031490,.00027968, .00024438]
    [.000012055, .000015435, .000020132, .000024537, .000027363, .000031474, .000034148, .000038092, .000040707, .000047260, .000051904, .000050545, .000048987, .000050916, .000054467, .000058545, .000062797, .000067094, .000071361, .000075511, .000079416, .000082870, .000085564, .000087071, .000086890, .000084564, .000079873, .000073010, .000064594, .000055517, .000046596, .000038510, .000031579, .000025837, .000021331, .000017868, .000015273, .000013377, .000012027, .000011099, .000010590, .000010228, .000010051, .000010016]
    ];

figure(5), plot(Tviscosity.', viscosity.');
title('viscosity')
ylabel('temperature')
legend(gasNames)



Tall= {Tconductivity Tdensity Tenthalpy TspecificHeat Tviscosity};
Pall= {conductivity density enthalpy specificHeat viscosity};
T= sort(unique([Tconductivity Tdensity Tenthalpy TspecificHeat Tviscosity]));

nProps=5;
nGasses=length(gasNames);
props= zeros([nProps length(T) nGasses]);
for i=1:nProps
    for j=1:nGasses
        props(i,:,j)= interp1(Tall{i}, Pall{i}(j,:), T);

    end
    figure(i), hold on, plot(T.',permute(props(i,:,:),[2 3 1]),'x'), hold off
end

for i=1:length(gasNames)
    fid=fopen([strtok(gasNames{i}) '.txt'],'w');

    Tstr=num2str(T);

    theStr=[];
    while ~isempty(Tstr)
        [tok Tstr]= strtok(Tstr);
        theStr = [theStr tok ',  '];
    end
    theStr(end-2:end)=[];
    fprintf(fid,'%s\n',theStr)

    for j=1:nProps
        Pstr= num2str(props(j,:,i));
        theStr=[];
        while ~isempty(Pstr)
            [tok Pstr]= strtok(Pstr);
            theStr = [theStr tok ',  '];
        end
        theStr(end-2:end)=[];
        fprintf(fid,'%s\n',theStr)
    end
    fclose(fid)
end
fclose all